package com.tedu.bank_ems1.service.impl;


import com.tedu.bank_ems1.dao.UserDao;
import com.tedu.bank_ems1.dao.impl.UserDaoImpl;
import com.tedu.bank_ems1.entity.User;
import com.tedu.bank_ems1.service.UserService;

/**
 * Author：毕龙
 * Date: 2024/6/24 14:36
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();

    @Override
    public User getUserByUsername(User user) {

        // 1.先判断用户的名字
        if (user.getUsername() == null) {
            throw new RuntimeException("用户名不能为空！");
        }

        //2.通过用户进行查询
        //调用数据层
        User userData = userDao.getUserByUsername(user.getUsername());

        //3.在判断用户是否存在
        if (userData == null) {
            throw new RuntimeException("此用户不存在！");
        }

        //4.存在进行密码判断
        if (user.getPassword() == null) {
            throw new RuntimeException("用户密码不能为空！");
        }

        if (!user.getPassword().equals(userData.getPassword())) {
            throw new RuntimeException("用户密码错误！");
        }


        return userData;
    }
}
